import numpy as np
import matplotlib.pyplot as plt

data=np.loadtxt(r'../data/ex1data1.txt',delimiter=',')
print(data.shape)

x=data[:,:-1]
y=data[:,-1]

X=np.c_[np.ones(len(x)),x]

def model(x,theta):
    return x.dot(theta)

def cost(y,h):
    return 1/(len(x)*2)*(h-y).T.dot(h-y)

theta=np.linalg.inv(X.T.dot(X)).dot(X.T.dot(y))

# print(theta)

plt.scatter(x,y)
plt.plot(x,model(X,theta),c='r')
plt.show()